<template>
  <Form ref="baseInfoFormRef" :items="items" split-col="1" width="500px" style="margin-top: 20px;padding-right: 100px;"
          label-width="100" :show-reset="showReset" @validateSuccess="validateSuccess" :rules="rules">

  </Form>
</template>

<script setup>

import Form from "@/components/plugs/form/Form.vue";
import {FormItemType} from "@/components/plugs/form/DialogFormInterface.js";
import {inject, ref, toRaw} from "vue";
import {AXIOS_NAME} from "@/constant/constant.js"
import {ElMessage} from "element-plus";

const $axios = inject(AXIOS_NAME);

const showReset = false;
const baseInfoFormRef = ref(null);

let items = [];
items.push({type: FormItemType.INPUT_HIDDEN,label: 'id',name: 'id'});
items.push({type: FormItemType.CUSTOMIZE_SELECT,label: '镜像名称',name: 'dockerImages.id',
  url: '/images/getImageList',textFiled:'name',valueField: "id"});
items.push({type: FormItemType.INPUT_TEXT,label: '容器名称',name: 'containerName',property:{'readonly': true}});
items.push({type: FormItemType.CUSTOMIZE_SELECT,label: '容器类型',name: 'containerType',
  url: '/dictionary/getDicDataByGroupId?groupId=container_type',textFiled:'text',valueField: "val",defaultValue:'1'});
items.push({type: FormItemType.CUSTOMIZE_SELECT,label: '是否可进入',name: 'hasEnter',
  url: '/dictionary/getDicDataByGroupId?groupId=has_enter',textFiled:'text',valueField: "val",defaultValue:'1'});
items.push({type: FormItemType.INPUT_TEXT,label: '进程名',name: 'processName'});
items.push({type: FormItemType.INPUT_TEXT,label: '运行模式',name: 'runModel'});

const rules = {
  containerName: [
    { required: true, message: '请选择容器', trigger: 'blur' }
  ],
  imageName: [
    { required: true, message: '请选择镜像', trigger: 'blur' }
  ],
  processName: [
    { required: true, message: '请填写进程名', trigger: 'blur' }
  ],
  runModel: [
    { required: true, message: '请填写运行模式', trigger: 'blur' }
  ],
};

const validateSuccess = (data) =>{
  data.testModels = [{"name":"2131231"}];
  data.tags = ["1",'2','3'];
  $axios.post('/deploy/updateBaseInfo',data).then(response => {
    const data = response.data;
    if(data.code == 1){
      ElMessage.info(data.msg);
      return;
    }
    ElMessage.error(data.msg);
  });
}


const setData = (data) =>{
  baseInfoFormRef.value.setData(toRaw(data));
}

defineExpose({setData});

</script>

<style scoped>

</style>